package codeRandomThoughts.Test300最长递增子序列;

public class Solution {
    public int lengthOfLIS(int[] nums) {
        int len = nums.length;

        //dp[i]:以nums[i]为结尾的最长递增子序列的长度
        int[] dp = new int[len];

        //初始化
        dp[0] = 1;

        //开始递推
        for (int i = 1; i < len; i++) {
            dp[i] = 1;
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
                }
            }
        }

        int maxLen = 0;
        for (int j : dp) {
            if (j > maxLen) {
                maxLen = j;
            }
        }

        return maxLen;
    }
}
